package cn.acheng.cams.trigger.http;

import cn.acheng.cams.domain.user.model.dto.LoginDTO;
import cn.acheng.cams.domain.user.model.dto.LogonDTO;
import cn.acheng.cams.domain.user.model.vo.LoginResult;
import cn.acheng.cams.domain.user.service.IUserService;
import cn.acheng.cams.trigger.http.response.Response;
import cn.acheng.cams.type.common.Constants;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/user")
public class UserController {


    @Resource
    private IUserService userService;

    @PostMapping("/login")
    public Response<LoginResult> login(@RequestBody LoginDTO loginDTO){
        LoginResult loginResult = userService.login(loginDTO);
        return Response.<LoginResult>builder()
                .data(loginResult)
                .info(Constants.ResponseCode.SUCCESS.getInfo())
                .code(Constants.ResponseCode.SUCCESS.getCode())
                .build();
    }


    @PostMapping("/logon")
    public Response<String> logon(@RequestBody LogonDTO logonDTO){
        String result = userService.logon(logonDTO);
        return Response.<String>builder()
                .data(result)
                .info(Constants.ResponseCode.SUCCESS.getInfo())
                .code(Constants.ResponseCode.SUCCESS.getCode())
                .build();
    }

}
